﻿package mortal.game.view.copy.QuestionCopy.panel
{
    import Message.Public.*;
    import com.gengine.core.frame.*;
    import com.gengine.resource.*;
    import com.mui.controls.*;
    import com.mui.display.*;
    import extend.language.*;
    import flash.events.*;
    import flash.geom.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.scene3D.map3D.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.copy.*;
    import mortal.game.view.copy.QuestionCopy.data.*;
    import mortal.game.view.vip.panel.*;
    import mortal.mvc.core.*;

    public class QuestionCopyInfoPanel extends CopyInfoPanelBase
    {
        protected var _bg:ScaleBitmap;
        protected var _title:GTextFiled;
        protected var _leftDes:GBitmap;
        protected var _rightDes:GBitmap;
        protected var _sorceDes:GBitmap;
        protected var _numBg2:GBitmap;
        protected var _numBg3:GBitmap;
        protected var _numBg1:GBitmap;
        protected var _leftNum:BitmapNumberText;
        protected var _rightNum:BitmapNumberText;
        protected var _socre:BitmapNumberText;
        protected var _rewardDouble:GLoadingButton;
        protected var _threeTimeBtn:GLoadingButton;
        protected var _doubleDes:GTextFiled;
        protected var _tipBtn:GLoadingButton;
        protected var _threeDes:GTextFiled;
        protected var _rewTipDes:GTextFiled;
        protected var _expDes:GBitmap;
        protected var _numBg4:GBitmap;
        protected var _exp:BitmapNumberText;
        protected var _vipTip:VipOpenTipsPanel;
        protected var _threeBp:GImageBitmap;
        protected var _threeNum:BitmapNumberText;
        private var _isUILoad:Boolean = false;
        private var _info:Object;
        private var _glowTime:SecTimer;
        private var _dragRect:Rectangle;
        private static var _instance:QuestionCopyInfoPanel;

        public function QuestionCopyInfoPanel()
        {
            this._dragRect = new Rectangle();
            super(ImagesConst.copyInfoPanelTitle_questionCopy);
            this.layer = LayerManager.uiLayer;
            this.mouseEnabled = true;
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            LoaderHelp.addResCallBack(ResFileConst.questionCopy, this.onShowWin);
            return;
        }// end function

        private function onShowWin() : void
        {
            this._isUILoad = true;
            this._bg = UIFactory.bg(0, 0, 253, 352, _bodySprite, ImagesConst.TaskTrack_Bg);
            _moveBtn.move(27, 29);
            _btnUnExpand.move(216, 28);
            this._title = UIFactory.gTextField("" + Language.getString(70958), 65, 27, 130, 20, _bodySprite, GlobalStyle.textFormatAnjin.setSize(15).center().setBold(true));
            this._leftDes = UIFactory.gBitmap(ImagesConst.QuestionCopyInfoLeftTitle, 30, 69, _bodySprite);
            this._rightDes = UIFactory.gBitmap(ImagesConst.QuestionCopyInfoRightTitle, 28, 101, _bodySprite);
            this._sorceDes = UIFactory.gBitmap(ImagesConst.QuestionCopyInfoSorceTitle, 29, 135, _bodySprite);
            this._numBg2 = UIFactory.gBitmap(ImagesConst.QuestionCopyInfoNumBg, 101, 95, _bodySprite);
            this._numBg3 = UIFactory.gBitmap(ImagesConst.QuestionCopyInfoNumBg, 101, 128, _bodySprite);
            this._numBg1 = UIFactory.gBitmap(ImagesConst.QuestionCopyInfoNumBg, 101, 62, _bodySprite);
            this._leftNum = UIFactory.bitmapNumberText(135, 64, "QuestionCopyNum.png", 18, 25, -2, _bodySprite, 13, 0);
            this._rightNum = UIFactory.bitmapNumberText(134, 98, "QuestionCopyNum.png", 18, 25, -2, _bodySprite, 13, 0);
            this._socre = UIFactory.bitmapNumberText(135, 131, "QuestionCopyNum.png", 18, 25, -2, _bodySprite, 13, 0);
            this._rewardDouble = UIFactory.gLoadingButton(ImagesConst.SkillRuneLevelUpBtn_upSkin, 52, 230, 148, 30, _bodySprite);
            this._rewardDouble.label = "";
            this._threeTimeBtn = UIFactory.gLoadingButton(ImagesConst.SkillRuneLevelUpBtn_upSkin, 52, 266, 148, 30, _bodySprite);
            this._threeTimeBtn.label = "";
            this._doubleDes = UIFactory.gTextField("" + Language.getString(70959), 73, 231, 120, 25, _bodySprite, GlobalStyle.textFormatPutong.setColor(16777215).setSize(16));
            this._tipBtn = UIFactory.gLoadingButton(ImagesConst.SkillRuneLevelUpBtn_upSkin, 52, 302, 148, 30, _bodySprite);
            this._tipBtn.label = "";
            this._threeDes = UIFactory.gTextField("" + Language.getString(70960), 152, 268, 120, 25, _bodySprite, GlobalStyle.textFormatPutong.setColor(16777215).setSize(16));
            this._rewTipDes = UIFactory.gTextField("" + Language.getString(70961), 93, 305, 100, 25, _bodySprite, GlobalStyle.textFormatPutong.setColor(16777215).setSize(16));
            this._expDes = UIFactory.gBitmap(ImagesConst.QuestionCopyInfoExpTitle, 29, 167, _bodySprite);
            this._numBg4 = UIFactory.gBitmap(ImagesConst.QuestionCopyInfoNumBg, 105, 162, _bodySprite);
            this._exp = UIFactory.bitmapNumberText(134, 163, "QuestionCopyNum.png", 18, 25, -2, _bodySprite, 13, 0);
            this._exp.text = "25466";
            this._threeBp = UIFactory.gImageBitmap("vipOpenTips_39_1.png", 53, 271, _bodySprite);
            this._threeNum = UIFactory.bitmapNumberText(87, 272, "vipTipsNumber.png", 19, 19, -9, _bodySprite, 11, 1);
            this._threeNum.text = "2";
            this._vipTip = UIFactory.getUICompoment(VipOpenTipsPanel, 8, 189, _bodySprite);
            this._vipTip.valueType = VipOpenTipsPanel.percentValue;
            this._vipTip.resetLevelTextPos(75, 9, 75, 9);
            this._vipTip.resetValueTextPos(175, 8, 175, 8);
            this._vipTip.bgUrl = ImagesConst.vipOpenTipsBg_mid;
            this._vipTip.vipType = EVipRecordType._EVipRecordTypeQuestionExp;
            this._leftNum.text = "0";
            this._rightNum.text = "0";
            this._socre.text = "0";
            this._title.text = "" + Language.getString(60252);
            this._rewTipDes.text = "" + Language.getString(60258);
            var _loc_2:Boolean = false;
            this._rewTipDes.mouseEnabled = false;
            var _loc_2:* = _loc_2;
            this._threeDes.mouseEnabled = _loc_2;
            this._doubleDes.mouseEnabled = _loc_2;
            this._rewardDouble.configEventListener(MouseEvent.CLICK, this.onDoubleCk);
            this._threeTimeBtn.configEventListener(MouseEvent.CLICK, this.onDoubleCk);
            this._tipBtn.configEventListener(MouseEvent.CLICK, this.showTipPanel);
            NetDispatcher.dispatchCmd(ServerCommand.QuestionScoreUpdate, null);
            NetDispatcher.addCmdListener(ServerCommand.VipLevelUp, this.updateVip);
            var _loc_1:* = QuestionCopyDataUtil.getInfo(Cache.instance.question.playInfo);
            this.updateInfo(_loc_1);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            NetDispatcher.removeCmdListener(ServerCommand.VipLevelUp, this.updateVip);
            this._info = null;
            this._isUILoad = false;
            this._bg.dispose(param1);
            this._title.dispose(param1);
            this._leftDes.dispose(param1);
            this._rightDes.dispose(param1);
            this._sorceDes.dispose(param1);
            this._numBg2.dispose(param1);
            this._numBg3.dispose(param1);
            this._numBg1.dispose(param1);
            this._leftNum.dispose(param1);
            this._rightNum.dispose(param1);
            this._socre.dispose(param1);
            this._rewardDouble.dispose(param1);
            this._threeTimeBtn.dispose(param1);
            this._doubleDes.dispose(param1);
            this._tipBtn.dispose(param1);
            this._threeDes.dispose(param1);
            this._rewTipDes.dispose(param1);
            this._bg = null;
            this._title = null;
            this._leftDes = null;
            this._rightDes = null;
            this._sorceDes = null;
            this._numBg2 = null;
            this._numBg3 = null;
            this._numBg1 = null;
            this._leftNum = null;
            this._rightNum = null;
            this._socre = null;
            this._rewardDouble = null;
            this._threeTimeBtn = null;
            this._doubleDes = null;
            this._tipBtn = null;
            this._threeDes = null;
            this._rewTipDes = null;
            this._expDes = null;
            this._numBg4 = null;
            this._exp = null;
            this._threeBp = null;
            this._threeNum = null;
            this._vipTip = null;
            if (this._glowTime)
            {
                this._glowTime.stop();
                this._glowTime.reset();
                this._glowTime = null;
            }
            return;
        }// end function

        public function updateVip(param1:Object = null) : void
        {
            var _loc_2:* = QuestionCopyDataUtil.getInfo(Cache.instance.question.playInfo);
            this.updateInfo(_loc_2);
            return;
        }// end function

        private function setThreeEn(param1:Boolean) : void
        {
            this._threeTimeBtn.enabled = param1;
            if (param1)
            {
                this._threeTimeBtn.filters = null;
                this._threeBp.filters = null;
                this._threeNum.filters = null;
                this._threeDes.filters = null;
            }
            else
            {
                this._threeTimeBtn.filters = [FilterConst.colorFilter2];
                this._threeBp.filters = [FilterConst.colorFilter2];
                this._threeNum.filters = [FilterConst.colorFilter2];
                this._threeDes.filters = [FilterConst.colorFilter2];
            }
            return;
        }// end function

        public function updateInfo(param1:Object = null) : void
        {
            this._info = param1;
            if (param1 == null)
            {
                return;
            }
            if (this._isUILoad == false)
            {
                return;
            }
            this._rightNum.text = "" + param1.rightNum;
            this._socre.text = "" + param1.socre;
            this._exp.text = "" + param1.exp;
            this._doubleDes.text = "" + Language.getStringByParam(60256, param1.curDouble, param1.doubleTotal);
            this._threeDes.text = "(" + param1.curThree + "/" + param1.threeTotal + ")";
            if (param1.hasUsePro)
            {
                this.setBtn(false);
                this.setThreeEn(false);
            }
            else
            {
                this.setBtn(true);
                if (param1.curDouble == 0)
                {
                    this._rewardDouble.enabled = false;
                }
                else
                {
                    this._rewardDouble.enabled = true;
                }
                if (param1.curThree == 0)
                {
                    this.setThreeEn(false);
                }
                else
                {
                    this.setThreeEn(true);
                }
            }
            if (QuestionCopyDataUtil.canShowCountDownPane())
            {
                this.setBtn(false);
                this.setThreeEn(false);
            }
            this.updateLeftNum();
            return;
        }// end function

        public function updateLeftNum() : void
        {
            if (this._isUILoad == false)
            {
                return;
            }
            var _loc_1:int = 0;
            if (Cache.instance.question && Cache.instance.question.curQuesInfo)
            {
                _loc_1 = Cache.instance.question.curQuesInfo.questionIndex;
            }
            var _loc_2:* = QuestionCopyDataUtil.TotalNum - _loc_1;
            this._leftNum.text = "" + _loc_2;
            return;
        }// end function

        public function showRightEffect() : void
        {
            if (this._isUILoad == false)
            {
                return;
            }
            if (this._glowTime == null)
            {
                this._glowTime = new SecTimer(9);
                this._glowTime.addListener(TimerType.ENTERFRAME, this.stopGlow);
            }
            this._glowTime.start();
            EffectManager.glowFilterReg(this._rightNum, [FilterConst.chatTipsFilter], 0.6, 20, 2, 0);
            EffectManager.glowFilterReg(this._socre, [FilterConst.chatTipsFilter], 0.6, 20, 2, 0);
            EffectManager.glowFilterReg(this._exp, [FilterConst.chatTipsFilter], 0.6, 20, 2, 0);
            return;
        }// end function

        private function stopGlow(param1:Object) : void
        {
            EffectManager.glowFilterUnReg(this._rightNum);
            EffectManager.glowFilterUnReg(this._socre);
            EffectManager.glowFilterUnReg(this._exp);
            if (this._glowTime)
            {
                this._glowTime.stop();
            }
            return;
        }// end function

        private function setBtn(param1:Boolean) : void
        {
            var _loc_2:* = param1;
            this._threeTimeBtn.enabled = param1;
            this._rewardDouble.enabled = _loc_2;
            return;
        }// end function

        protected function onShowHideHandler(event:MouseEvent) : void
        {
            switch(event.currentTarget)
            {
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        private function onDoubleCk(event:MouseEvent) : void
        {
            var _loc_2:int = 2;
            if (event.currentTarget == this._rewardDouble)
            {
                _loc_2 = 2;
            }
            else
            {
                _loc_2 = 3;
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.CopyQuestionUseProp, _loc_2));
            return;
        }// end function

        private function showTipPanel(event:MouseEvent) : void
        {
            var _loc_2:Object = {x:this._tipBtn.x, y:this._tipBtn.y};
            Dispatcher.dispatchEvent(new DataEvent(EventName.CopyQuestioInfoTipBtnCk, _loc_2));
            return;
        }// end function

        override public function show(param1:int = 0, param2:int = 0) : void
        {
            super.show(param1, param2);
            this.stageResize();
            return;
        }// end function

        override public function stageResize() : void
        {
            super.stageResize();
            x = SceneRange.display.width - 246 - 30;
            y = 200 - 15;
            return;
        }// end function

        public static function get hasInstance() : Boolean
        {
            return _instance != null;
        }// end function

        public static function get isInView() : Boolean
        {
            return _instance != null && !_instance.isHide;
        }// end function

        public static function get instance() : QuestionCopyInfoPanel
        {
            if (_instance == null)
            {
                _instance = new QuestionCopyInfoPanel;
            }
            return _instance;
        }// end function

    }
}
